package com.pubinfo.passbook.esb.controller;

import com.alibaba.fastjson.JSONObject;
import com.pubinfo.passbook.common.model.eop.ApplyParam;
import com.pubinfo.passbook.common.model.eop.OrderParam;
import com.pubinfo.passbook.eop.EopDubboService;
import com.pubinfo.passbook.eop.service.EopApiService;
import com.pubinfo.uop.dubbo.api.UopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

@Slf4j
@RestController
@Api(tags = "CRM相关接口")
@RequestMapping(value = "eop")
public class EopController {
  
  @Resource
  private EopDubboService eopDubboService;
  @Resource
  EopApiService apiService;
  
  @Resource
  private UopService uopService;
  
  @PostMapping("placeOrder")
  @ApiOperation(value = "CRM订单受理")
  public JSONObject placeOrder(@RequestBody @Valid ApplyParam applyParam) {
    return eopDubboService.placeOrder(applyParam);
  }
  
  
  @PostMapping("order")
  @ApiOperation(value = "CRM订单-直接调用")
  public Map<String, Object> order(@RequestBody @Valid OrderParam orderParam) {
    Map<String, Object> result = uopService.uopServiceCall(orderParam.getHeadMap(), orderParam.getBodyMap(), orderParam.getExtMap());
    return result;
  }
  
  @GetMapping("invoiceRefresh")
  @ApiOperation(value = "统一平台发票申请结果反刷")
  public String invoiceRefresh(String systemNbr,
                               String orderNum,
                               String codeNumber,
                               Long lanId,
                               String status,
                               String errorInfo,
                               String bssOrderNum,
                               String crmOrderNum) {
    return apiService.invoiceRefresh(systemNbr, orderNum, codeNumber, lanId, status, errorInfo, bssOrderNum, crmOrderNum);
  }
}
